package leetCode.secondWeek;

public class Code_53 {
  public int maxSubArray(int[] nums) {
    int res = nums[0];
    int sum = 0;
    for (int i = 0; i < nums.length; i++) {
      if (sum > 0) {
        sum += nums[i];
      } else {
        sum = nums[i];
      }
      res = res > sum ? res : sum;
    }
    return res;
  }
}
